home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / pcfig4th.zip / 4TH-UG.DOC < prev    next >
Text File  |  1985-10-21  |  95KB  |  2,153 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.                                      User's Guide for
  12.  
  13.  
  14.                                    8086/8088 Fig-FORTH
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.                                        Release 1.0
  22.  
  23.                                   With Compiler Security
  24.                                            and
  25.                                   Variable Length Words
  26.  
  27.  
  28.                                         March 1981
  29.  
  30.  
  31.  
  32.                              ================================
  33.  
  34.  
  35.                            MS-DOS File Interface and Revisions
  36.  
  37.                                         July 1983
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.                This program and documentation are released  to  the  public
  45.                domain.  The FIG-FORTH listing  is  made  available  by  the
  46.                FORTH Interest Group, PO Box 1105, San Carlos, CA 94070
  47.  
  48.                Modified for MS-DOS and documented by J.E.   Smith,  U.   of
  49.                Penn./Dept.of  Chem,  Philadelphia,  PA   19104   (to   whom
  50.                inquiries should be directed). 
  51.  
  52.                Any  further  distribution  of  this  software  is  strictly
  53.                encouraged, as long as you don't get rich and  keep  it  all
  54.                for yourself. 
  55.  
  56.                If you modify this revised version  and  re-distribute  your
  57.                own version, it would be polite  to  notify  the  author  of
  58.                these  revisions,  and  to  take  responsibility  for   your
  59.                modifications. 
  60.  
  61.           8086/8088 Fig-FORTH User's Guide                      Page 2
  62.  
  63.  
  64.  
  65.  
  66.  
  67.           2  QUICK REFERENCE
  68.  
  69.           This is a summary of information necessary to use  FIG-FORTH
  70.           and it's documentation. 
  71.  
  72.  
  73.           2.1  System Requirements
  74.  
  75.           FORTH requires the following system resources:
  76.  
  77.                 * an 8086 or 8088 CPU running MS-DOS version  1.10  or
  78.                   1.25
  79.  
  80.                 * 64K of available RAM, or about 100K total
  81.  
  82.                 * one or two disk drives
  83.  
  84.  
  85.  
  86.           2.2  Invocation
  87.  
  88.           FORTH is started by typing the following in response to  the
  89.           COMMAND prompt. 
  90.  
  91.                    FORTH <commands>
  92.  
  93.           Where <commands> is an optional list of FORTH  words  to  be
  94.           executed. 
  95.  
  96.           FORTH normally uses a special disk.  To  use  MS-DOS  files,
  97.           the following commands are available:
  98.  
  99.                    A:                      selects drive A
  100.                    B:                      selects drive B
  101.                    DIR" <filename>"        lists matching file information
  102.                    FILES" <filename>"      lists matching file names
  103.                    USING" <filename>"      selects <filename> for screen access
  104.                    EOF                     closes current screen file
  105.                    LOAD" <filename>"       loads the screens in <filename>
  106.                    ERASE" <filename>"      erases any matching files
  107.  
  108.  
  109.           Note:   NEVER change any disk while  FORTH  is  using  a
  110.                   file on that  disk!   Study  the  section  below
  111.                   regarding disk operations. 
  112.  
  113.  
  114.           8086/8088 Fig-FORTH User's Guide                      Page 3
  115.  
  116.  
  117.  
  118.  
  119.  
  120.           2.3  Provided Documentation
  121.  
  122.           This document contains three main sections:
  123.  
  124.                 * FORTH user's guide
  125.                   The user's guide tells you how to  use  the  special
  126.                   features in this version of FORTH. 
  127.  
  128.                 * FORTH technical reference
  129.                   The   technical   reference   contains   information
  130.                   regarding modifications and additions to  the  FORTH
  131.                   interpreter/compiler    relative    to    the    FIG
  132.                   implementation. 
  133.  
  134.                 * FORTH glossary
  135.                   This is a list and explanation of  each  FORTH  word
  136.                   which has been changed or added to this  version  of
  137.                   FORTH. 
  138.  
  139.  
  140.           8086/8088 Fig-FORTH User's Guide                      Page 4
  141.  
  142.  
  143.  
  144.  
  145.  
  146.           3  INTRODUCTION
  147.  
  148.           This document describes changes and additions  to  FIG-FORTH
  149.           v1.0 which is distributed by the
  150.  
  151.                    FORTH Interest Group
  152.                    P.O. Box 1105
  153.                    San Carlos, CA 94070
  154.  
  155.           as modified to run under MS-DOS by
  156.  
  157.                    Joe Smith
  158.                    University of Pennsylvania
  159.                    Dept. of Chemistry
  160.                    250 S. 33rd St. 
  161.                    Philadelphia, PA 19104
  162.  
  163.           This  software  and  the   accompanying   documentation   is
  164.           available from
  165.  
  166.                    SIG/86
  167.                    c/o Joseph Boykin
  168.                    47-4 Sheridan Dr. 
  169.                    Shrewsbury, MA 01545
  170.  
  171.           This  version  of  FIG-FORTH  incorporates   a   number   of
  172.           significant changes to the FIG version.  The following is  a
  173.           partial list:
  174.  
  175.                 * written for Microsoft's MACRO-86 assembler
  176.  
  177.                 * full MS-DOS file interaction, as well as usual FORTH
  178.                   disk access
  179.  
  180.                 * all i/o is vectored and may  be  re-directed  within
  181.                   FORTH
  182.  
  183.                 * command line interpretation
  184.  
  185.  
  186.           Modifications   to   the   FIG-FORTH   implementation   were
  187.           undertaken to alleviate several problems.   First,  the  FIG
  188.           version is  for  CP/M-86.   Once  FORTH  was  running  under
  189.           MS-DOS,  the  lack  of  a   file   interface   soon   became
  190.           intolerable.   Also,  the  assembly   source   for   Seattle
  191.           Computer's assembler was not transportable to  other  MS-DOS
  192.           systems.  The translation to Microsoft's MACRO-86 was  begun
  193.           in January  of  1983  and  the  file  system  interface  was
  194.           completed the following June. 
  195.  
  196.           My original goal was to install a language for my  own  use.
  197.           That is still my primary concern.  Accordingly, this version
  198.           of the language is recommended for people who  are  familiar
  199.  
  200.           8086/8088 Fig-FORTH User's Guide                      Page 5
  201.  
  202.  
  203.  
  204.           with  their  computer,  and  (somewhat   less   importantly)
  205.           familiar with FORTH.  If you are new to FORTH, you will have
  206.           to dig for some of the  basic  information.   (some  helpful
  207.           references are listed at the end of this guide).  If you are
  208.           a person who enjoys understanding  and  tinkering  with  the
  209.           mechanisms (read 'hacker') you should feel  right  at  home.
  210.           If you are an experienced FORTH wizard, you can tell me  all
  211.           the things I did wrong! 
  212.  
  213.           The author (J.E.S.) gratefully acknowledges the  efforts  of
  214.           the FORTH Interest Group in  providing  FORTH  source  code.
  215.           FORTH owes much of it's  popularity  to  the  work  of  this
  216.           organization, it was the first significant software  to  run
  217.           on my system (even before I had disks) and without them this
  218.           implementation would certainly not exist. 
  219.  
  220.           Also, special  thanks  to  Joseph  Boykin,  whose  TOP  text
  221.           processor formatted this document.  
  222.           8086/8088 Fig-FORTH User's Guide                      Page 6
  223.  
  224.  
  225.  
  226.  
  227.  
  228.           4  USER'S GUIDE
  229.  
  230.           This documentation presents specific  details  necessary  to
  231.           use this version of FORTH under MS-DOS.  It is not a  user's
  232.           guide to FORTH in general.  Several introductory  references
  233.           are given at the end of this guide
  234.  
  235.  
  236.           4.1  System requirements
  237.  
  238.           The FORTH interpreter/compiler as distributed requires:
  239.  
  240.                 * an 8086/8088 computer running MS-DOS version 1.10 or
  241.                   1.25
  242.  
  243.                 * 64K of RAM, or 96K total,  including  the  operating
  244.                   system
  245.  
  246.                 * one or more disk drives
  247.  
  248.           These  requirements   may   be   changed   to   almost   any
  249.           configuration by changing options in the assembly source and
  250.           re-assembling.  This process requires:
  251.  
  252.                 * All of the above requirements, plus another  64K  of
  253.                   RAM, or 128K total (for MACRO-86)
  254.  
  255.                 * the MACRO-86 macro assembler, or it's equivalent
  256.  
  257.                 * the LINK-86 linker, or it's equivalent
  258.  
  259.                 * the EXE2BIN program to convert the linker output  to
  260.                   a .COM file
  261.  
  262.           See the section below, "Modifying FORTH", and the  technical
  263.           reference for further information.  
  264.           8086/8088 Fig-FORTH User's Guide                      Page 7
  265.  
  266.  
  267.  
  268.  
  269.  
  270.           4.2  FORTH, calculator style
  271.  
  272.           The simplest mode of interaction with FORTH is  through  the
  273.           system console.  You type commands,  FORTH  interprets  them
  274.           and carries out your  orders;  much  the  same  as  using  a
  275.           powerful, programmable calculator. 
  276.  
  277.  
  278.           4.2.1  Getting Started
  279.  
  280.           FORTH is invoked from MS-DOS by typing:
  281.  
  282.                    FORTH <optional command list>
  283.  
  284.           in response to COMMAND's prompt.  This will load and execute
  285.           the FORTH interpreter.  FORTH  will  initialize  itself  and
  286.           print a banner something like
  287.  
  288.                    8086 Fig-FORTH Version 1.1A
  289.  
  290.           Then, FORTH begins executing any commands you give  it.   If
  291.           there  was  anything  else  on  the   command   line,   i.e.
  292.           <command list> was present, FORTH attempts to interpret  it.
  293.           Thus, if you wanted to find out what 8086  is  in  hex,  you
  294.           could type:
  295.  
  296.                    A:FORTH 8086 HEX . BYE
  297.  
  298.           and FORTH would reply:
  299.  
  300.                    8086 Fig-FORTH Version 1.1A
  301.  
  302.                    1F96
  303.                    A:
  304.  
  305.           If nothing was passed on  the  command  line,  FORTH  simply
  306.           types a carriage return and waits for you.  The command list
  307.           is limited to a total of  80  characters.   If  you  type  a
  308.           carriage return at this point, FORTH should  respond:  "ok".
  309.           If it doesn't, you have a problem. 
  310.  
  311.  
  312.           4.2.2  Communicating With FORTH
  313.  
  314.           Keyboard entries are  handled  by  the  FORTH  word  EXPECT.
  315.           EXPECT only recognizes two special keys: <DELETE> and  <CR>.
  316.           Any other key is presumed  to  be  a  valid  character.   No
  317.           MS-DOS editing functions are available.  The exact key which
  318.           FORTH recognizes as <DELETE> defaults to  ASCII  DEL.   This
  319.           may be easily changed to any other key.  The  section  below
  320.           on  modifying  FORTH  tells  how  to  change  the  backspace
  321.           character.  If you type <DELETE>,  EXPECT  will  delete  the
  322.           last character entered.  If you try to go past the beginning
  323.  
  324.           8086/8088 Fig-FORTH User's Guide                      Page 8
  325.  
  326.  
  327.  
  328.           of the line, the terminal should beep and leave  the  cursor
  329.           in the first column. 
  330.  
  331.  
  332.           4.2.3  Special Functions
  333.  
  334.           While no editing functions are provided, MS-DOS does respond
  335.           to some other special  keys.   Any  console  output  may  be
  336.           paused by typing ^S.  Printer output is toggled using ^P/^N.
  337.           Because MS-DOS intercepts these keys, FORTH will  never  see
  338.           them.  Another function, the interrupt key ^C, has  variable
  339.           effects.   Normally,  pressing  ^C  causes   the   currently
  340.           executing FORTH word to be interrupted.  Control  is  passed
  341.           to the FORTH word (ABORT) which usually aborts  the  current
  342.           word and  resets  the  interpreter.   This  process  may  be
  343.           changed to  provide  more  intelligent  interrupt  handling.
  344.           Refer to the last part of the technical reference section on
  345.           "Modifying FORTH" for more information. 
  346.  
  347.           There are a number of assembly options which may affect  the
  348.           exact  way  these  keys  are  handled.   See  the  technical
  349.           reference section entitled "installation dependent code" for
  350.           further information. 
  351.  
  352.  
  353.           4.2.4  New definitions
  354.  
  355.           One command FORTH accepts is the  colon  ":".   Colon  is  a
  356.           command to begin compiling  the  following  text  as  a  new
  357.           definition.  No "ok" will appear until you have successfully
  358.           completed your definition and ended it with a semicolon ";".
  359.           The definition may be spread out over as many lines  as  you
  360.           need, up to 80 characters on each line.   Until  you  end  a
  361.           line by typing <CR>, you may back up and  change  it.   Once
  362.           you go on to the next line, no editing is  possible.   FORTH
  363.           will make you aware of any errors in the definition.  If you
  364.           make a mistake, the whole definition must be entered again. 
  365.  
  366.           Try the following definition:
  367.  
  368.                : STAR 42 EMIT ;
  369.  
  370.           FORTH should respond "ok" after you hit  return.   Now  test
  371.           STAR by typing: STAR<CR>.  FORTH  should  print  "*ok".   If
  372.           that worked, try this one:
  373.  
  374.                : MILKY-WAY
  375.                  BEGIN
  376.                     STAR SPACE SPACE
  377.                     ?TERMINAL
  378.                  UNTIL ;
  379.  
  380.           Remember, no "ok" will  be  printed  until  you  finish  the
  381.           definition with  the  semicolon.   Any  leading  spaces  are
  382.           ignored.  Test MILKY-WAY as with STAR.  When you  get  tired
  383.  
  384.           8086/8088 Fig-FORTH User's Guide                      Page 9
  385.  
  386.  
  387.  
  388.           of star-gazing, stop the program by hitting  any  key.   The
  389.           stars  should  stop,  and  FORTH  should  inform  you   that
  390.           everything is "ok".  You can also  pause  the  execution  of
  391.           MILKY-WAY using ^S, or abort it using ^C. 
  392.  
  393.           You can experiment with other definitions, but having no way
  394.           of modifying  the  functions  without  re-typing  them  soon
  395.           becomes a serious problem.  The next section  tells  how  to
  396.           edit and load definitions stored on your  disk.   Don't  try
  397.           any disk operations until you have read the next section. 
  398.  
  399.  
  400.           4.2.5  Exiting FORTH
  401.  
  402.           To return to MS-DOS, say "BYE" to FORTH.  
  403.           8086/8088 Fig-FORTH User's Guide                     Page 10
  404.  
  405.  
  406.  
  407.  
  408.  
  409.           4.3  Using the Disk
  410.  
  411.           Standard FORTH supports only  the  most  primitive  of  file
  412.           structures.  FORTH views the  disk  as  a  linear  array  of
  413.           blocks which may be accessed in any  order.   A  disk  block
  414.           formatted as 16 lines of 64 characters is called  a  screen.
  415.           In  the  standard  configuration,  FIG-FORTH  bypasses   the
  416.           operating system file structure.  This means that FORTH must
  417.           have a disk all to itself.  While there  are  advantages  to
  418.           this  arrangement  (no  directory  overhead,   simple   disk
  419.           interface,  portability  across   operating   systems,   for
  420.           instance),  it  is  often  inconvenient  that  FORTH  should
  421.           totally ignore it's host operating system's files. 
  422.  
  423.           To deal with this conflict, and yet  maintain  compatibility
  424.           with standard FORTH disk access,  the  FIG-FORTH  model  was
  425.           changed.  The words which do all disk access, BLOCK-READ and
  426.           BLOCK-WRITE, can now be assigned to any function.  Thus,  by
  427.           telling BLOCK-READ/WRITE to use a file instead of  the  disk
  428.           directly, all of the standard FORTH disk words will refer to
  429.           blocks of that file.  The user can easily switch between the
  430.           two modes, or use one exclusively.  Also, all of  the  usual
  431.           disk words will work on a file as  well  as  the  old  FORTH
  432.           disk. 
  433.  
  434.  
  435.           4.3.1  Creating and editing Definitions
  436.  
  437.           There  are  three  editors  distributed  with  the  package.
  438.           Unfortunately, there isn't time or space to  describe  their
  439.           use  here.   All  are  described  elsewhere,  however.   The
  440.           editors provided include:
  441.  
  442.                 * two line-oriented editors: the  FORTH  Inc.   editor
  443.                   described in Leo Brodie's "STARTING FORTH"  and  the
  444.                   FIG   portable   editor   described   in   the   FIG
  445.                   installation manual. 
  446.  
  447.                 * a screen editor described  in  Dr.   Dobb's  Journal
  448.                   No. 59.  This editor is configured for the Televideo
  449.                   950 terminal, and must be  modified  for  any  other
  450.                   terminal. 
  451.  
  452.           Any of these may be used with either screen files  or  FORTH
  453.           disks.  All examples in this guide will refer to the  editor
  454.           described by Brodie, which has been compiled and included in
  455.           the FORTH.COM file. 
  456.  
  457.           8086/8088 Fig-FORTH User's Guide                     Page 11
  458.  
  459.  
  460.  
  461.           4.3.2  FORTH Disk Access
  462.  
  463.           After a COLD start, any disk words will access a FORTH disk.
  464.           If you start FORTH and type "4 LIST",  it  assumes  you  are
  465.           asking to see the fourth disk block.  In this mode, all disk
  466.           transfers bypass the file system.  The user  has  access  to
  467.           all blocks on the  disk,  and  if  more  than  one  disk  is
  468.           available, FORTH will treat them as one disk  of  twice  the
  469.           capacity. 
  470.  
  471.           Once you use a screen file, you must execute SWITCH  to  get
  472.           back to the FORTH disk.  This should remind you to  "switch"
  473.           your FIG-FORTH disk for the MS-DOS disk. 
  474.  
  475.           The disk interface allows you to use only one  format  at  a
  476.           time.   That  is,  FORTH  cannot  automatically   adapt   to
  477.           different  FORTH  disk  formats  the  way  MS-DOS  can.   By
  478.           changing the constants  that  describe  the  disk,  you  can
  479.           manually change formats to any supported by your i/o system. 
  480.  
  481.           To find what format FORTH expects, type
  482.  
  483.                    B/BUF REC/BLK / . 
  484.  
  485.           This gives the sector  size  in  bytes.   To  determine  the
  486.           capacity of the disk FORTH expects,  display  the  constants
  487.           BLK/DRIVE, MAXDRIVE, and MAXBLOCK. 
  488.  
  489.           The 8-inch format is 128 bytes/sector, 52 sectors/track,  77
  490.           tracks per disk.  The 5-inch disks are 512  bytes/sector,  8
  491.           sectors/track, 40 tracks per disk. 
  492.  
  493.  
  494.  
  495.           4.3.3  Screen File Access
  496.  
  497.           This version of FORTH includes an interface  to  the  MS-DOS
  498.           file system.  The assembly source includes a low level  file
  499.           interface, but the higher level functions must  be  compiled
  500.           from a  FORTH  disk.   See  the  following  section  in  the
  501.           technical reference on "Modifying FORTH"  for  details.   In
  502.           order to switch from the FORTH disk to a screen file, type
  503.  
  504.                    USING" <filename>"
  505.  
  506.           where <filename> is any legal, unambiguous MS-DOS  filename.
  507.           FORTH will attempt to open the file and determine if it is a
  508.           file of FORTH screens.  If all goes well,  FORTH  will  tell
  509.           you how many blocks are available in that  file.   The  file
  510.           will look just like the disk to FORTH, except it's  capacity
  511.           will be smaller.  Screen files may not span disks.   If  the
  512.           specified file doesn't exist, FORTH will create it but  will
  513.           not  allocate  any  space  to  it.   The  following  example
  514.           demonstrates the screen file access words. 
  515.  
  516.           8086/8088 Fig-FORTH User's Guide                     Page 12
  517.  
  518.  
  519.  
  520.           Start FORTH, and type
  521.  
  522.                    USING" TRYIT"
  523.  
  524.           FORTH will create a file named TRYIT.SCR and tell  you  that
  525.           the file is empty.  To use the file, you must allocate  some
  526.           space to it.  This is done by entering
  527.  
  528.                    2 EXTEND
  529.  
  530.           EXTEND takes the number on the  stack  and  adds  that  many
  531.           blocks to the end of the screen file.   In  this  case,  the
  532.           file is now 0+2 or 2 screens long (screens 0 and 1).  If you
  533.           were to try and list screen 2, you would get an error.  Note
  534.           that EXTEND does not put anything in the screens  allocated;
  535.           they contain whatever the disk held previously, but now they
  536.           belong to your current screen file.  Clear a working  screen
  537.           by entering the editor and filling screen one with blanks:
  538.  
  539.                    1 SCR ! 
  540.                    EDITOR
  541.                    WIPE
  542.  
  543.           List the screen, select line 0, and enter some text:
  544.  
  545.                    L
  546.                    0 T
  547.                    P ( this is screen 0 line 1 in file TRYIT.SCR )
  548.                    L
  549.  
  550.           Use FLUSH to save the changes, then  type  "L"  again.   The
  551.           screen should be just as  you  left  it.   Try  editing  the
  552.           definitions for STAR and MILKY-WAY onto this  screen.   When
  553.           you finish editing, save it by typing
  554.  
  555.                    EOF
  556.  
  557.           (End Of File) to close the file.  EOF displays the directory
  558.           entry of your file to verify that  everything  is  allright.
  559.           If the file is empty, EOF will notify you and then erase the
  560.           file. 
  561.  
  562.           You are now in limbo as far as the disk  is  concerned.   If
  563.           you try to access the disk, FORTH will remind you to specify
  564.           which kind of disk access you want  to  do:  file  or  FORTH
  565.           disk.  To list the screen again, tell FORTH to use TRYIT.SCR
  566.           (USING" TRYIT").  Now FORTH should find a file with 2 blocks
  567.           in it.  And  if  you  list  screen  1,  you  will  see  your
  568.           definitions, just as  you  left  them.   If  you  need  more
  569.           screens, use  EXTEND  as  before  to  allocate  more  space.
  570.           Remember to WIPE the screen as it will probably be  full  of
  571.           nasty control characters for your terminal to choke on! 
  572.  
  573.           Why not use screen 0?  Well, FORTH can list  screen  0,  and
  574.           you can edit text there, but if you try "0 LOAD", FORTH will
  575.  
  576.           8086/8088 Fig-FORTH User's Guide                     Page 13
  577.  
  578.  
  579.  
  580.           get very confused.  When FORTH compiles block 0, it actually
  581.           compiles input from the console.   Thus,  block  0  of  each
  582.           screen file cannot be loaded (but, see the following section
  583.           for one use for screen 0). 
  584.  
  585.  
  586.  
  587.           4.3.4  Compiling Definitions
  588.  
  589.  
  590.           As with editing, once you have opened a screen file, you can
  591.           proceed exactly as you would with a FORTH disk.  If you have
  592.           edited some definitions  onto  screen  1,  compile  them  by
  593.           typing 1 LOAD.  If FORTH says "ok", test them as before.  If
  594.           there is an error, edit the definitions and try again. 
  595.  
  596.           There is only one new word with  regard  to  loading  screen
  597.           files.  To make the process of selecting a screen  file  and
  598.           loading it more convenient, use. 
  599.  
  600.                    LOAD" <filename>"
  601.  
  602.           LOAD" opens  the  specified  file,  and  loads  the  screens
  603.           starting with screen one.  Since screen zero is just sitting
  604.           there with nothing to do, LOAD" lists  it  before  beginning
  605.           the load with screen one.  This is  a  good  place  for  any
  606.           special       messages,        advertisements,        secret
  607.           messages...whatever.  LOAD" is defined as simply:
  608.  
  609.                    : LOAD"
  610.                         USING"
  611.                         ( code to list screen 0 )
  612.                         1 LOAD
  613.                         EOF ;
  614.  
  615.           If an error is encountered during the LOAD, that  file  will
  616.           be the current screen file.  
  617.           8086/8088 Fig-FORTH User's Guide                     Page 14
  618.  
  619.  
  620.  
  621.  
  622.  
  623.           4.3.5  Other Functions
  624.  
  625.           There are several utility functions defined which make FORTH
  626.           more convenient to use with the file  system.   These  words
  627.           apply only to MS-DOS disks and not to FORTH disks. 
  628.  
  629.  
  630.           4.3.5.1  changing the default drive
  631.  
  632.           As in COMMAND, typing
  633.  
  634.                    A:
  635.           or
  636.                    B:
  637.  
  638.           will change the default drive for all file access. 
  639.  
  640.  
  641.           4.3.5.2  directory information
  642.  
  643.           Several utilities are available for using MS-DOS disks.  Two
  644.           words which list the disk directory are defined:
  645.  
  646.                    DIR"   <filename>"
  647.                    FILES" <filename>"
  648.  
  649.           DIR" gives a complete directory  listing  of  each  matching
  650.           filename, similar to the MS-DOS DIR command.   FILES"  lists
  651.           only filenames, five  per  line,  much  as  the  MS-DOS  DIR
  652.           command with the "/W" option.  The exact  interpretation  of
  653.           ambiguous filenames differs from  COMMAND's.   The  filename
  654.           must not be blank,  and  any  part  of  the  name  left  out
  655.           defaults to "*".  Thus,
  656.  
  657.                    DIR" .SCR"     = DIR *.SCR
  658.                    DIR" *"        = DIR *
  659.                    DIR" ALL."     = DIR ALL.*
  660.  
  661.           The trailing quote may be replaced with the carriage return,
  662.           and in fact, must be replaced to list  files  with  a  blank
  663.           extension:
  664.  
  665.                    DIR" .<CR>     =DIR *. 
  666.                    DIR" INDEX.<CR>=DIR INDEX. 
  667.  
  668.  
  669.           4.3.5.3  erasing files
  670.  
  671.           A function is provided to erase files:
  672.  
  673.                    ERASE" <filename>"
  674.  
  675.           The use of this command is similar to  the  directory  words
  676.  
  677.           8086/8088 Fig-FORTH User's Guide                     Page 15
  678.  
  679.  
  680.  
  681.           above, except that no  part  of  <filename>  has  a  default
  682.           value.  ERASE"  will  accept  ambiguous  filenames,  and  it
  683.           displays the name of each file it  erases.   No  warning  is
  684.           issued when the filename is "*.*", so beware! 
  685.  
  686.  
  687.           4.3.5.4  screen transfer
  688.  
  689.           To assist in copying screens between FORTH disks and  MS-DOS
  690.           files, two utilities are provided: COPY>FILE  and  COPY>SCR.
  691.           These function very simply.   COPY>FILE  directs  all  block
  692.           reads to the FIG-FORTH disk, and  all  disk  writes  to  the
  693.           current screen file.  COPY>SCR does the reverse.   Then  all
  694.           you need is the usual words for moving screens  around,  and
  695.           magically they appear at the destination.  The  actual  copy
  696.           operation is provided by the word #SCRCOPY, which takes  the
  697.           starting source screen, the starting destination screen  and
  698.           the number of screens to copy off the stack.  Thus,
  699.  
  700.                    USING" NEW"
  701.                    COPY>FILE ... 
  702.                    100 1 14 #SCRCOPY
  703.                    EOF
  704.  
  705.           would copy screens 100-113 on the FORTH disk to screens 1-14
  706.           in the file NEW.SCR.  Note that after you type  COPY>SCR  or
  707.           COPY>FILE, you can still LIST or INDEX the  source  disk  if
  708.           you forget which screens you want to copy. 
  709.  
  710.  
  711.           4.3.5.5  screen file status
  712.  
  713.           To check on the status of the current screen file,  you  can
  714.           use
  715.  
  716.                    SCREENS /? 
  717.  
  718.           If the screen file is in use, a display similar to the  DIR"
  719.           information is printed; for example,
  720.  
  721.                    A:FORTH   .SCR r w s     10240  06-28-1983  19:59
  722.  
  723.           If the EOF command is given and then /?   is  repeated,  the
  724.           following would be printed:
  725.  
  726.                    A:FORTH   .SCR r w s
  727.  
  728.           showing that the file is not in use.  The  "r w s"  indicate
  729.           that this is a screen or random access file (s),  which  may
  730.           be both read from (r) and written to (w). 
  731.  
  732.           An interesting discrepancy may arise between the DIR" report
  733.           and the /?  information.  
  734.           8086/8088 Fig-FORTH User's Guide                     Page 16
  735.  
  736.  
  737.  
  738.           Examine the following session:
  739.  
  740.                    USING" NEW" empty file
  741.                    5 EXTEND ok
  742.                    DIR" NEW.SCR" 
  743.                    B:NEW     .SCR          0  06-29-1983   0:26   1 file ok
  744.                    SCREENS /? 
  745.                    B:NEW     .SCR r w s       5120  06-29-1983   0:27    ok
  746.                    EOF ok
  747.                    B:NEW     .SCR       5120  06-29-1983   0:27   1 file ok
  748.                    SCREENS /? 
  749.                    B:NEW     .SCR r w s   ok
  750.  
  751.           The differences in the file size and time fields reflect the
  752.           operating system buffering the physical disk output.  The /?
  753.           display is taken from the  file  control  block  in  memory,
  754.           which is immediately updated,  while  the  DIR"  display  is
  755.           taken from the directory and is not updated  until  data  is
  756.           written to the disk when the file is closed by EOF.  
  757.           8086/8088 Fig-FORTH User's Guide                     Page 17
  758.  
  759.  
  760.  
  761.  
  762.  
  763.           4.3.5.6  Notes
  764.  
  765.           A  few  features  of  the  above  discussion  bear   further
  766.           emphasis. 
  767.  
  768.                 * NEVER change the disk FORTH  is  using  for  screens
  769.                   while the file is open.  Changing disks  haphazardly
  770.                   is a bad practice in almost all cases, not just  for
  771.                   FORTH.  As can be seen above, the  information  kept
  772.                   on the disk is not always accurate.  If the disk  is
  773.                   changed, the file parameters kept in memory will  be
  774.                   separated from the directory entry for the file, and
  775.                   disaster is almost certain to result. 
  776.  
  777.                 * In light of the above comments, note  that  you  may
  778.                   FLUSH FORTH's disk buffers, but  not  MS-DOS's  disk
  779.                   buffers.  Thus your disk buffers are not  guaranteed
  780.                   to be on the disk until you  close  the  file  using
  781.                   EOF.  If  the  file  interface  is  loaded,  BYE  is
  782.                   redefined to execute EOF before  exiting,  to  force
  783.                   any updated buffers to be saved. 
  784.  
  785.                 * Only one screen file may be active at  once.   FORTH
  786.                   checks this and will not allow another USING"  while
  787.                   the SCREENS file is in use.  This  restriction  only
  788.                   applies to screen files. 
  789.  
  790.                 * The FORTH disk is the default state after COLD,  but
  791.                   before an EOF.  You must specifically request access
  792.                   to a screen file.  Once you use a screen file, FORTH
  793.                   blocks any FORTH disk access until  you  request  it
  794.                   using SWITCH.  Accessing an MS-DOS disk as  a  FORTH
  795.                   disk probably won't destroy it, however, FORTH  will
  796.                   probably get upset and quit talking to  you.   FORTH
  797.                   tries to remind you to pay attention, but it doesn't
  798.                   try to protect you: the burden is  on  YOU  to  keep
  799.                   track of what you are doing! 
  800.  
  801.                 * There is a convention for  the  names  of  the  disk
  802.                   functions.  Since there are two names for each  file
  803.                   (see below) there are two ways to refer to  a  file.
  804.                   Names which begin with a "/" expect  an  address  on
  805.                   the stack.  Names which end in a double-quote expect
  806.                   a  filename,  delimited  by  a  trailing  quote,  to
  807.                   follow.  The  function  that  assigns  filenames  to
  808.                   files, therefore, has both: /IS". 
  809.  
  810.  
  811.           8086/8088 Fig-FORTH User's Guide                     Page 18
  812.  
  813.  
  814.  
  815.           4.4  Modifying FORTH
  816.  
  817.           FORTH is an extremely  flexible  language.   With  a  little
  818.           effort you can make it your own  personal  environment.   In
  819.           addition, since you have the assembly source you can  change
  820.           the inner workings, making it more efficient.  The following
  821.           discussion  is  not  complete,  but  serves   only   as   an
  822.           introduction.  Exploring the territory is half the fun! 
  823.  
  824.  
  825.           4.4.1  FORTH Extensions
  826.  
  827.  
  828.           One of the nice things about FORTH is the ability to  extend
  829.           the language.  To complement  this  extensibility,  you  can
  830.           save the new FORTH in an executable file and the  extensions
  831.           become immediately available.  Only two things are necessary
  832.           to accomplish this: first,  FORTH's  cold  start  parameters
  833.           must be  updated;  and  second,  the  memory  image  of  the
  834.           modified FORTH must be saved in a file.   This  is  how  the
  835.           FORTH.COM file was constructed for distribution. 
  836.  
  837.           Updating the cold start parameters is  accomplished  by  the
  838.           FORTH word NEW.  Saving the new version can be done  in  two
  839.           ways:  first,  using  DEBUG  and  second,  the  FORTH   word
  840.           SAVE-FORTH" <filename>".  The FORTH word  SIZE?   will  tell
  841.           you the size of the FORTH kernel for writing from DEBUG.  To
  842.           use SAVE-FORTH, first execute NEW to lock the changes.  Make
  843.           sure no files are open before executing NEW, otherwise  they
  844.           will appear to be open when the new  FORTH  executes.   Then
  845.           define an output file and use SAVE-FORTH to write itself  to
  846.           the file.  Since the file was defined after NEW, it will not
  847.           appear in the new version.  Study the following hypothetical
  848.           example:
  849.  
  850.                    9 LOAD 100 LOAD 108 LOAD ok
  851.                    NEW ok
  852.                    current version is A
  853.                    new version (A-Z)? Bok
  854.                    >FILE S4 ok
  855.                    S4 /SAVE-FORTH" X4TH.COM"
  856.                    B:X4TH    .COM      12521  06-29-1983   0:27 ok
  857.  
  858.           Note that because the FIG-FORTH disk is the  default  state,
  859.           you must always modify and load the file definitions from  a
  860.           FORTH disk.  If you FORGET the file words, you can only  use
  861.           the FORTH disk! 
  862.  
  863.  
  864.           4.4.2  Patching
  865.  
  866.           Many of the parameters which affect the operation  of  FORTH
  867.           are placed in the boot parameter area  at  the  low  end  of
  868.           FORTH.  These may be freely modified using  DEBUG,  or  from
  869.           within FORTH.  On execution of COLD, these  parameters  will
  870.  
  871.           8086/8088 Fig-FORTH User's Guide                     Page 19
  872.  
  873.  
  874.  
  875.           be used to initialize the interpreter.  The patches can then
  876.           be made permanent as  described  above.   For  example,  the
  877.           following will change the FORTH backspace key:
  878.  
  879.                    KEY 14 +ORIGIN ! 
  880.  
  881.           After you type this and hit return, FORTH will wait for  you
  882.           to hit a key.  The key you type will be placed in  the  boot
  883.           parameters and will be recognized as  your  backspace.   The
  884.           other parameters in this area are clearly commented  in  the
  885.           assembly source, should you want to patch any of them. 
  886.  
  887.  
  888.           4.4.3  Assembly Source Modifications
  889.  
  890.           Re-assembly  of  FORTH  is  the  least  desirable  form   of
  891.           modification.  It is slow and can  be  difficult  to  debug.
  892.           However, there are modifications which are only possible  in
  893.           this way.  A  great  deal  of  time  has  gone  into  adding
  894.           comments to the assembly source so that you  can  understand
  895.           the way FORTH works.  Almost all of the  comments  appearing
  896.           in the FIG listing are in the new listing, along  with  some
  897.           additional comments.   There  is  more  information  on  the
  898.           assembly source in the technical reference portion  of  this
  899.           documentation. 
  900.  
  901.           Be aware of two problems here: first, it  is  very  easy  to
  902.           lose track of the changes you make.  so document and comment
  903.           each modification.  Second, more changes make  your  version
  904.           of FORTH  more  unique  (or  maybe  just  strange)  and  any
  905.           definitions using that feature  less  portable.   Don't  add
  906.           bells and whistles just to be different.  
  907.           8086/8088 Fig-FORTH User's Guide                     Page 20
  908.  
  909.  
  910.  
  911.  
  912.  
  913.           5  TECHNICAL REFERENCE
  914.  
  915.           This section describes  changes  and  modifications  to  the
  916.           FIG-FORTH model.  It is not an explanation of the FIG model,
  917.           nor of how FORTH works.  The user should refer  to  the  FIG
  918.           installation manual for further information. 
  919.  
  920.  
  921.           5.1  Assembly Source
  922.  
  923.           The FIG assembly listing on which this version is based  was
  924.           written for the CPM/86 8086 assembler.  For MS-DOS, the  FIG
  925.           listing was translated  into  source  for  Seattle  Computer
  926.           Products 8086 assembler.   Since  the  latter  assembler  is
  927.           peculiar to SCP systems, the code was translated again  into
  928.           source for  Microsoft's  MACRO-86  macro  assembler,  to  be
  929.           portable to any MS-DOS environment. 
  930.  
  931.           Several features of MACRO-86 were used  to  provide  greater
  932.           flexibility.  First, macros were written to build dictionary
  933.           headers for each definition.  These macros make  setting  up
  934.           the dictionary entries  convenient,  but  more  importantly,
  935.           they calculate the link fields.  Because the  links  are  no
  936.           longer  based  on  specific  labels  in  the   source,   the
  937.           dictionary can be split into several files  which  are  then
  938.           INCLUDED at  the  appropriate  points.   This  allows  great
  939.           flexibility and modularity in assembling FORTH. 
  940.  
  941.  
  942.           5.1.1  Source File Organization
  943.  
  944.           The source is now broken into several separate files:
  945.  
  946.                 * 4TH-MAIN.ASM
  947.                   This is the primary file which INCLUDES  the  others
  948.                   during assembly.  It contains the inner interpreter,
  949.                   code-level kernel, and most of the FORTH vocabulary. 
  950.  
  951.                 * 4TH-SYSD.ASM
  952.                   This file contains (almost) all of the code which is
  953.                   operating system  or  hardware  dependent.   If  you
  954.                   wanted to transport FORTH  to  a  different  system,
  955.                   most of the changes would be in this file. 
  956.  
  957.                 * 4TH-DISK.ASM
  958.                   This file is INCLUDED by 4TH-SYSD and  contains  the
  959.                   actual  disk  interface  for  reading/writing   disk
  960.                   sectors. 
  961.  
  962.                 * 4TH-FILE.ASM
  963.                   Also (optionally) INCLUDED by SYSD,  this  file  has
  964.                   all of  the  words  that  deal  with  files  at  the
  965.                   operating system level.  This code is only assembled
  966.  
  967.           8086/8088 Fig-FORTH User's Guide                     Page 21
  968.  
  969.  
  970.  
  971.                   if the FILES option is set to TRUE. 
  972.  
  973.                 * 4TH-XTNS.ASM
  974.                   These definitions are code-level extensions  of  the
  975.                   FORTH dictionary.  These  include  array  addressing
  976.                   primitives, long fetch and store operators  and  the
  977.                   port i/o words.  MATCH is also in this  file.   This
  978.                   file is only assembled if the EXTEND option is TRUE. 
  979.  
  980.                 * 4TH-OPTS.H
  981.                   The assembly options  are  located  in  this  header
  982.                   file,  and  are  symbols  which   begin   with   the
  983.                   underscore character.  These are  global  parameters
  984.                   and are used by other modules.   All  other  equates
  985.                   and variables should be local to  the  module  where
  986.                   they are defined. 
  987.  
  988.                   It  is  unfortunate  that  the  modules  cannot   be
  989.                   separately assembled and linked.  The present system
  990.                   requires a lot of memory  and  about  5  minutes  to
  991.                   assemble (on an 8MHz  8086  using  8"  ssdd  disks).
  992.                   This is really tedious for making small changes! 
  993.  
  994.  
  995.           5.1.2  Macros
  996.  
  997.                   The macros necessary to assemble FORTH  are  in  the
  998.                   file 4TH-LIB.MAC.  Comments in this file explain the
  999.                   function  of  each  macro.   Beside  the  dictionary
  1000.                   macros, there are two macros to do branches  in  the
  1001.                   threaded definitions.  The  actions  of  the  macros
  1002.                   should be clear after studying their definitions and
  1003.                   the manner in which they are used in the code. 
  1004.  
  1005.  
  1006.           5.1.3  Comments
  1007.  
  1008.                   The  SCP  assembler  source  was   rather   sparsely
  1009.                   commented.  This  omission  has  been  rectified  by
  1010.                   copying all of the FIG listing comments,  plus  some
  1011.                   additional comments, into  the  MACRO-86  code.   In
  1012.                   addition, each entry in the dictionary has a comment
  1013.                   in the following form:
  1014.  
  1015.                   ;=AB  <name>   <description>   <stack effects>
  1016.  
  1017.                   where  A  is  a  letter  indicating  the   type   of
  1018.                   dictionary entry, and B is  a  character  indicating
  1019.                   whether the function has  been  added  or  modified.
  1020.                   This scheme  allows  automatic  glossary  generation
  1021.           using a text editor or search utility.  
  1022.           8086/8088 Fig-FORTH User's Guide                     Page 22
  1023.  
  1024.  
  1025.  
  1026.                   The dictionary entry types are:
  1027.  
  1028.                            C = code-level definition
  1029.                            : = colon definition
  1030.                            # = constant
  1031.                            ? = variable
  1032.                            U = user variable
  1033.  
  1034.                   The B character is either a blank,  a  plus,  or  an
  1035.                   asterisk;  indicating   that   the   definition   is
  1036.                   unmodified, added, or modified, respectively. 
  1037.  
  1038.  
  1039.           5.2  Modifications
  1040.  
  1041.                   The changes to the FIG listing fall  basically  into
  1042.                   two  categories:  changes  to  clean  up  the   disk
  1043.                   interface and manage buffers more  efficiently,  and
  1044.                   changes to route the i/o functions through execution
  1045.                   vectors.   The  sections  below  describe   specific
  1046.                   changes to the FIG model.  Each section  corresponds
  1047.                   to one in the FIG-FORTH  installation  manual.   Any
  1048.                   changes to that part of the model are listed there. 
  1049.  
  1050.  
  1051.           5.2.1  boot parameters
  1052.  
  1053.                        BSIN was changed to 127 - ASCII DEL. 
  1054.  
  1055.  
  1056.           5.2.2  machine code definitions
  1057.  
  1058.                        Code added to  (FIND)  to  handle  word-aligned
  1059.                   definitions.  May be disabled by setting the  option
  1060.                   ALIGN to FALSE. 
  1061.  
  1062.  
  1063.           5.2.3  high-level utility definitions
  1064.  
  1065.                        1+ and 2+ were changed to code definitions. 
  1066.                        TRAVERSE was modified  to  handle  word-aligned
  1067.                   LFA's. 
  1068.                        PFA was changed to handle word-aligned PFA's. 
  1069.                        EXPECT backspace was made destructive. 
  1070.                        ID.   was  modified  to  reset  MSB   of   last
  1071.                   character. 
  1072.                        CREATE  can  compile  dictionary  headers  with
  1073.                   word-aligned LFA's.  If DP is  odd  after  compiling
  1074.                   the name field, DP is incremented so that  the  rest
  1075.                   of the definition lies is word addressable.  If byte
  1076.                   values such as character  strings  are  subsequently
  1077.                   compiled into the definition, the alignment  may  be
  1078.                   lost.  Note that the length byte at NFA still  gives
  1079.                   the exact length of the name,  but  not  necessarily
  1080.                   the displacement to the LFA.  The alignment  may  be
  1081.  
  1082.           8086/8088 Fig-FORTH User's Guide                     Page 23
  1083.  
  1084.  
  1085.  
  1086.                   disabled by setting the ALIGN  option  to  FALSE  at
  1087.                   assembly time to save space. 
  1088.                        QUIT prints lower case "ok". 
  1089.                        ABORT prints the user version as well. 
  1090.                        COLD sets execution vectors. 
  1091.                        All system dependent  initialization  is  in  a
  1092.                   subroutine called SYSINIT, located in  4TH-SYSD.ASM,
  1093.                   which is called just prior  to  starting  the  inner
  1094.                   interpreter. 
  1095.  
  1096.  
  1097.           5.2.4  installation dependent code
  1098.  
  1099.  
  1100.  
  1101.           5.2.4.1  console i/o
  1102.  
  1103.                        KEY, EMIT, and  CR  were  changed  to  use  the
  1104.                   execution vectors @KEY, @EMIT, and @CR respectively.
  1105.                   These vectors are initialized to the CFA's of (KEY),
  1106.                   (EMIT) and (CR); but may be changed by  storing  new
  1107.                   CFA's in the vectors. 
  1108.                        Two options in 4TH-OPTS.H affect  console  i/o:
  1109.                   DIRECTCON and IOBITS.  If DIRECTCON is TRUE, console
  1110.                   i/o is performed by MS-DOS function six  and  seven,
  1111.                   which ignore all special characters.  Thus,  if  you
  1112.                   have an application which has to respond to ^P,  for
  1113.                   example, you should re-assemble with  DIRECTCON  set
  1114.                   to TRUE.  IOBITS is an equate which  determines  how
  1115.                   many bits to send/receive.  Normal  ASCII  terminals
  1116.                   don't use  the  MSB,  so  IOBITS  should  be  seven.
  1117.                   However, the IBM-PC uses all eight bits,  so  IOBITS
  1118.                   should  be  eight.   DIRECTCON  also   disables   ^C
  1119.                   interrupts, except during printer output. 
  1120.  
  1121.  
  1122.           5.2.4.2  printer i/o
  1123.  
  1124.                        The variable  controlling  printer  output  was
  1125.                   changed to PRINTER.  If PRINTER is zero, no  printer
  1126.                   output occurs.  If PRINTER is positive, all  console
  1127.                   output also goes to  the  printer.   If  PRINTER  is
  1128.                   negative, output normally going to  the  console  is
  1129.                   sent only to the printer. 
  1130.  
  1131.  
  1132.           5.2.4.3  disk i/o
  1133.  
  1134.                        The code to interface to the disk was  factored
  1135.                   into two parts.  All functions that  know  something
  1136.                   about the physical characteristics of the  disk  are
  1137.                   in the  4TH-DISK.ASM  file.   Every  other  function
  1138.                   knows only that disk blocks  are  1024  bytes  long.
  1139.                   This means that BLOCK-READ/WRITE must always deliver
  1140.                   1024 bytes and not one physical sector. 
  1141.  
  1142.           8086/8088 Fig-FORTH User's Guide                     Page 24
  1143.  
  1144.  
  1145.  
  1146.                        The  disk  read/write   routines   (BLOCK-READ,
  1147.                   BLOCK-WRITE)  were  changed  to  use  the  execution
  1148.                   vectors @BLKRD and @BLKWRT.  For normal  FORTH  disk
  1149.                   i/o, @BLKRD and @BLKWRT point to BLKRD  and  BLKWRT.
  1150.                   For screen file access, these  vectors  are  set  to
  1151.                   /BLOCK-READ and /BLOCK-WRITE. 
  1152.                        The variables DRIVE, RECORD,  REC/BLK  and  DTA
  1153.                   are set to the parameters used for each disk  access
  1154.                   and  may  be  examined  if  an  error  occurs.   The
  1155.                   variable DISK-ERROR is set to indicate  the  success
  1156.                   or failure of each disk operation.  If DISK-ERROR is
  1157.                   zero,  the  operation  was  successful.    Otherwise
  1158.                   DISK-ERROR has the MS-DOS error code as described in
  1159.                   it's documentation, except  that  write  errors  are
  1160.                   converted to negative numbers. 
  1161.                        The  buffer   management   was   also   changed
  1162.                   slightly.  When BUFFER has to flush a dirty block to
  1163.                   the disk, it checks and flushes ALL  dirty  buffers.
  1164.                   This requires very little additional  overhead,  and
  1165.                   it is  much  more  efficient  for  copying  multiple
  1166.                   blocks. 
  1167.  
  1168.           5.2.5  high-level definitions
  1169.  
  1170.           5.2.6  system tools
  1171.  
  1172.           5.2.7  RAM workspace
  1173.  
  1174.  
  1175.           5.2.8  memory map
  1176.  
  1177.                        The memory map was  extended  to  use  all  64K
  1178.                   (LIMIT=0), and 8 1K byte block buffers. 
  1179.  
  1180.  
  1181.           5.2.9  other
  1182.  
  1183.                        COLD  sets  the  ^C  interrupt  vector  to  the
  1184.                   address of  a  code  fragment  which,  on  receiving
  1185.                   control after you  hit  ^C,  examines  the  variable
  1186.                   @BREAK.  If @BREAK is zero,  the  interrupt  handler
  1187.                   simply returns  from  the  interrupt  and  execution
  1188.                   continues.  Unfortunately, a "^C" is always sent  to
  1189.                   the console, and the key is not passed to FORTH.  If
  1190.                   @BREAK is non-zero, the  interrupt  handler  vectors
  1191.                   the inner interpreter to the (presumed CFA)  address
  1192.                   in @BREAK.  @BREAK is set at assembly  time  to  the
  1193.                   CFA of (ABORT), it is not initialized by  COLD.   If
  1194.                   the DIRECTCON option  is  selected,  almost  all  ^C
  1195.                   processing  is  disabled.   The  only  time   a   ^C
  1196.                   interrupt can occur is during printer output. 
  1197.                        BYE exits via INT 20H
  1198.  
  1199.           8086/8088 Fig-FORTH User's Guide                     Page 25
  1200.  
  1201.  
  1202.  
  1203.           5.3  Additions
  1204.  
  1205.                   Two new features have been added in this version  of
  1206.                   FIG FORTH.   Command  line  argument  interpretation
  1207.                   allows  you  to  pass  instructions  to  FORTH  from
  1208.                   COMMAND.  Thus, you can run FORTH from a batch  file
  1209.                   if the program doesn't require any  terminal  input.
  1210.                   The file interface allows FORTH to share information
  1211.                   with other MS-DOS programs and utilities. 
  1212.  
  1213.  
  1214.           5.3.1  Command Line Interpretation
  1215.  
  1216.                   When FORTH starts execution, it copys any string  of
  1217.                   text on the  command  line  to  the  terminal  input
  1218.                   buffer, and interprets it just as if you  had  typed
  1219.                   it. 
  1220.  
  1221.  
  1222.           5.3.2  File Interface
  1223.  
  1224.                   The goal in developing the  file  interface  was  to
  1225.                   allow FORTH  useful  access  to  MS-DOS  files,  not
  1226.                   simply the random access  screens.   The  constraint
  1227.                   was that it had to be accomplished with a minimum of
  1228.                   change to the FIG model.  This discussion is not  as
  1229.                   complete as it could be.  The  reason  for  this  is
  1230.                   that the details will probably  change.   While  the
  1231.                   overall design is (hopefully) sound, the fine points
  1232.                   are not completely worked out.  As they are applied,
  1233.                   they will certainly be improved. 
  1234.  
  1235.                   There are two parts to the file interface:  the  low
  1236.                   level functions defined in 4TH-FILE.ASM and the high
  1237.                   level words in FILES.SCR.  The  low-level  functions
  1238.                   are little more  than  MS-DOS  function  calls  with
  1239.                   FORTH headers.  The high-level definitions  do  most
  1240.                   of  the  work,  making  it  easier  to  modify   the
  1241.                   interface. 
  1242.  
  1243.                   The words defined in FILES.SCR allow you  to  define
  1244.                   files in much the same  way  you  define  variables.
  1245.                   After a file has been defined, the name is  used  to
  1246.                   refer to it.  The name acts just  like  a  variable,
  1247.                   returning an address.  The  address  returned  is  a
  1248.                   pointer to the file header and file  control  block,
  1249.                   or FCB.  The header is a  word  of  data  where  the
  1250.                   file's attributes are kept, this header  address  is
  1251.                   referred to as the file descriptor,  or  FD.   These
  1252.                   attributes are only used by FORTH, MS-DOS never sees
  1253.                   them.  At present, the only  attributes  are:  read,
  1254.                   write, sequential/random access and open.  Following
  1255.                   the header is the FCB which MS-DOS  uses  while  the
  1256.                   file is open. 
  1257.  
  1258.           8086/8088 Fig-FORTH User's Guide                     Page 26
  1259.  
  1260.  
  1261.  
  1262.                   The first part of the FCB is the filespec.  This  is
  1263.                   the drive, filename and extension for the file,  and
  1264.                   is the name by which  MS-DOS  refers  to  the  file.
  1265.                   Before opening a file, these fields must  be  filled
  1266.                   in.  Assigning the filename is accomplished  by  two
  1267.                   methods, one for interactive use  and  one  for  use
  1268.                   inside definitions.  The word FNAME takes  a  target
  1269.                   address and a mode number on  the  stack.   It  then
  1270.                   parses the string at PAD (actually PAD+1, PAD  holds
  1271.                   the count byte), and returns a flag which is true if
  1272.                   the filename was ambiguous.  If FNAME finds that the
  1273.                   given filename is illegal (or  null)  it  prints  an
  1274.                   error and aborts. 
  1275.  
  1276.                   To assign a filename to a file  from  the  terminal,
  1277.                   the word /IS" is provided.  This function  takes  an
  1278.                   fd off the stack and assigns the following  word  in
  1279.                   the input stream as the filename.  The /IS" function
  1280.                   can be used in a definition, but it can't be used to
  1281.                   assign a filename to a file without console input. 
  1282.  
  1283.                   Once the file has been defined, and has a  name,  it
  1284.                   can be opened or created using  /OPEN,  or  /CREATE.
  1285.                   The file can be closed using /CLOSE. 
  1286.  
  1287.                   For character files, /GETC and /PUTC are provided to
  1288.                   read/write  one  character;  and  /READ  and  /WRITE
  1289.                   transfer a number of bytes at  once.   Screen  files
  1290.                   use /BLOCK-READ and /BLOCK-WRITE.   These  functions
  1291.                   are  called   indirectly   through   BLOCK-READ   or
  1292.                   BLOCK-WRITE. 
  1293.  
  1294.                   This  reference  is  admittedly   incomplete.    For
  1295.                   further information, study the glossary for 4TH-FILE
  1296.           and the FORTH code for the file interface.  
  1297.           8086/8088 Fig-FORTH User's Guide                     Page 27
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.           6  GLOSSARY
  1304.  
  1305.                   This  section  is  a  glossary  of  words  added  or
  1306.                   changed, relative to FIG-FORTH v1.0.   The  name  of
  1307.                   the word is given, then it's stack effects, then the
  1308.                   type of definition, where the letter  indicates  the
  1309.                   type of definition:
  1310.  
  1311.                            C = code-level definition
  1312.                            : = colon definition
  1313.                            # = constant
  1314.                            ? = variable
  1315.                            U = user variable
  1316.  
  1317.                   and  the  second  letter   indicates   whether   the
  1318.                   definition was added  (+)  or  modified  (*).   And,
  1319.                   finally, the file where the word is defined. 
  1320.  
  1321.           8086/8088 Fig-FORTH User's Guide                     Page 28
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.           6.1  Assembly Listing Definitions
  1328.  
  1329.                   (2ARR)           n1 n2 PFA -- addr               C+ XTNS
  1330.                                   Two dimensional word array primitive
  1331.                   compiled  by  2ARRAY.   The  address  of  the  array
  1332.                   element at row n1, column n2, of an array  beginning
  1333.                   at addr+4 is left on the stack.  It is assumed  that
  1334.                   the number  of  columns  is  stored  at  addr.   The
  1335.                   contents of addr+2 could hold  the  number  of  rows
  1336.                   (perhaps for error checking), but it isn't  used  in
  1337.                   the calculation. 
  1338.  
  1339.                   (2CARR)          n1 n2 PFA -- addr2              C+ XTNS
  1340.                                   Two dimensional byte array primitive
  1341.                   compiled by  STRINGS.   The  address  of  the  array
  1342.                   element at row n1, column n2 of an  array  beginning
  1343.                   at PFA+4 is left on the stack.  It is  assumed  that
  1344.                   the row size is at PFA.  The contents of PFA+2 could
  1345.                   hold the number of rows, but it isn't  used  in  the
  1346.                   calculations. 
  1347.  
  1348.                   (ARRAY)          n PFA -- addr                   C+ XTNS
  1349.                                   Integer  array  primitive  used   by
  1350.                   ARRAY.  The address of the nth element of the  array
  1351.                   beginning at PFA+2 is calculated  and  left  on  the
  1352.                   stack.  The length of the array is stored at PFA. 
  1353.  
  1354.                   (BLKRD)          --                              C+ DISK
  1355.                                   Block  read  primitive   called   by
  1356.                   BLKRD.  This function calls the absolute  disk  read
  1357.                   function (INT 25) to access the disk.  This function
  1358.                   transfers REC/BLK records,  starting  at  RECORD  on
  1359.                   DRIVE to DTA.  The code returned by the interrupt is
  1360.                   placed in DISK-ERROR, zero indicating success. 
  1361.  
  1362.                   (BLKWRT)         --                              C+ DISK
  1363.                                   Block  write  primitive  called   by
  1364.                   BLKWRT.  This function transfers REC/BLK records  on
  1365.                   DRIVE starting at RECORD to DTA.   The  return  code
  1366.                   from INT 26H is negated and  placed  in  DISK-ERROR,
  1367.                   zero means success. 
  1368.  
  1369.                   (CARR)           n PFA -- addr                   C+ XTNS
  1370.                                   Byte  array  primitive  compiled  by
  1371.                   CARRAY.  The address of the  nth  character  in  the
  1372.                   array beginning at PFA+2 is calculated and  left  on
  1373.                   the stack.  The length of the array or  the  current
  1374.                   length of the string may be left at PFA. 
  1375.  
  1376.  
  1377.           8086/8088 Fig-FORTH User's Guide                     Page 29
  1378.  
  1379.  
  1380.  
  1381.                   (CLOSE)          FCB -- f                        C+ FILE
  1382.                                   Primitive  function  to  close   FCB
  1383.                   using  DOS  function  10H.   The  flag  is  zero  if
  1384.                   successful, 0FFH if not. 
  1385.  
  1386.                   (CREATE)         FCB -- f                        C+ FILE
  1387.                                   Create and open a file as  specified
  1388.                   in FCB using DOS function 16H.  The flag returned is
  1389.                   zero if successful, 0FFH if not. 
  1390.  
  1391.                   (FBLKRD)         FCB n -- f                      C+ FILE
  1392.                                   File  block  read  primitive.   This
  1393.                   function reads n  blocks  from  an  open  FCB.   The
  1394.                   blocks read are the size  specified  in  the  record
  1395.                   size field of the FCB.  For normal screen  files,  n
  1396.                   is always 1 and the  record  size  is  set  to  1024
  1397.                   bytes. 
  1398.  
  1399.                   (FBLKWRT)        FCB n -- f                      C+ FILE
  1400.                                   Write n blocks to the file specified
  1401.                   by FCB.  See (FBLKRD) above. 
  1402.  
  1403.                   (FIND)           a1 NFA -- [PFA b] f             C* MAIN
  1404.                                   (FIND)  was   modified   to   handle
  1405.                   aligned  dictionary  headers  (only  when  ALIGN  is
  1406.                   true).  The address list  following  the  header  is
  1407.                   aligned by inserting a  NOP  (90H)  after  the  last
  1408.                   character of the name field.  (FIND) must take  this
  1409.                   into account when looking up a name. 
  1410.  
  1411.                   (FNAME)          FCB addr1 n -- addr2 f          C+ FILE
  1412.                                   Parse  the  string  at  addr1  as  a
  1413.                   filename using mode n, and assign it  to  FCB.   The
  1414.                   first character not parsed and an ambiguous filename
  1415.                   are left on  the  stack.   This  function  uses  DOS
  1416.                   function 29H, which defines the modes. 
  1417.  
  1418.                   (OPEN)           FCB -- f                        C+ FILE
  1419.                                   Open the specified  FCB.   The  flag
  1420.                   returns the success or  failure  of  the  operation:
  1421.                   zero if successful, 0FFH otherwise. 
  1422.  
  1423.                   (READ)           FCB addr -- f                   C+ FILE
  1424.                                   Sequential      read      primitive.
  1425.                   Transfers the next record in the file  specified  by
  1426.                   FCB  to  addr.   The  status  of  the  operation  is
  1427.                   returned in  the  flag  f.   The  flag  is  zero  if
  1428.                   successful, 0FF if not. 
  1429.  
  1430.                   (WRITE)          FCB addr -- f                   C+ FILE
  1431.                                   Sequential write primitive.   Writes
  1432.                   the next record of the file specified  by  FCB  from
  1433.                   addr.  The flag returned by DOS function 15H is left
  1434.                   on the stack. 
  1435.  
  1436.           8086/8088 Fig-FORTH User's Guide                     Page 30
  1437.  
  1438.  
  1439.  
  1440.                   (XOF)                    n1 n2 -- [n1]           C+ XTNS
  1441.                                   Control structure primitive compiled
  1442.                   by OF.  If the case being scanned for  (n1)  matches
  1443.                   the current case (n2), the tag n1 is dropped and the
  1444.                   FORTH words following the branch compiled by OF  are
  1445.                   executed.  If the case tags don't match, n1 is  left
  1446.                   on the stack and the branch is executed to check the
  1447.                   next case. 
  1448.  
  1449.                   +BUF             addr1 -- addr2                  :* MAIN
  1450.                                   Advance the buffer pointer addr1  to
  1451.                   the next buffer at addr2. 
  1452.  
  1453.                   1-               n -- n-1                        C+ MAIN
  1454.                                   Subtract one from the item on top of
  1455.                   the stack. 
  1456.  
  1457.                   2-               n -- n-2                        C+ MAIN
  1458.                                   Subtract two from the item on top of
  1459.                   the stack. 
  1460.  
  1461.                   ?FIRST           FCB addr -- f                   C+ FILE
  1462.                                   Search the disk  directory  for  the
  1463.                   first occurance of FCB.  The flag returned  is  zero
  1464.                   if none are found, 0FF otherwise.   If  a  match  is
  1465.                   found, it's directory entry is placed at addr. 
  1466.  
  1467.                   ?NEXT            addr FCB -- f                   C+ FILE
  1468.                                   Search for  the  next  occurance  of
  1469.                   FCB.  The search FCB must previously have  been  set
  1470.                   up by ?FIRST.  If a match is found, f will  be  0FFH
  1471.                   and the matching directory entry  will  be  left  at
  1472.                   addr. 
  1473.  
  1474.                   @BLKRD           - addr                          U+ MAIN
  1475.                                   Execution vector holding the CFA  of
  1476.                   a function to read one block from  the  disk.   This
  1477.                   vector is either BLKRD  for  FORTH  disk  access  or
  1478.                   FBLKRD for screen file access.  BLOCK-READ uses this
  1479.                   vector. 
  1480.  
  1481.                   @BLKWRT          - addr                          U+ MAIN
  1482.                                   Execution vector holding the CFA  of
  1483.                   a function to write one block  to  the  disk.   This
  1484.                   vector is either BLKWRT for  FORTH  disk  access  or
  1485.                   FBLKWRT for screen file  access.   BLOCK-WRITE  uses
  1486.                   this vector. 
  1487.  
  1488.                   @BREAK           -- addr                                 ?+ SYSD
  1489.                                   Execution vector holding the CFA  of
  1490.                   the function to be executed on input if  a  ^C.   If
  1491.                   @BREAK  is  zero,  the  interrupt   handler   simply
  1492.                   returns, effectively ignoring the interrupt. 
  1493.  
  1494.  
  1495.           8086/8088 Fig-FORTH User's Guide                     Page 31
  1496.  
  1497.  
  1498.  
  1499.                   @CR              -- addr                                 U+ MAIN
  1500.                                   Execution   vector   to   output   a
  1501.                   newline,  usually  carriage  return/linefeed.   COLD
  1502.                   initializes @CR to the CFA of (CR). 
  1503.  
  1504.                   @EMIT            -- addr                                 U+ MAIN
  1505.                                   Execution  vector  to  do  character
  1506.                   output.  Initialized by COLD to the CFA of (EMIT). 
  1507.  
  1508.                   @KEY             -- addr                                 U+ MAIN
  1509.                                   Execution  vector  to  do  character
  1510.                   input.  Initialized by COLD to the CFA of (KEY). 
  1511.  
  1512.                   B/SEC            -- n                            C+ FILE
  1513.                                   Calls DOS function 1BH  and  returns
  1514.                   the number of bytes per physical disk sector. 
  1515.  
  1516.                   BLK/DRIVE        -- n                            #+ DISK
  1517.                                   Constant returning the number of  1K
  1518.                   disk blocks per drive. 
  1519.  
  1520.                   BLKRD            addr blk --                     :+ DISK
  1521.                                   This function  reads  block  blk  to
  1522.                   addr.  This is basically an  interface  between  the
  1523.                   BLOCK-READ function and the (BLKRD) functions. 
  1524.  
  1525.                   BLKWRT           addr blk --                     :+ DISK
  1526.                                   This function writes block blk  from
  1527.                   addr.  This is basically an  interface  between  the
  1528.                   BLOCK-WRITE function and the (BLKWRT) functions. 
  1529.  
  1530.                   BLOCK            n -- addr                       :* MAIN
  1531.                                   BLOCK was modified to  check  for  a
  1532.                   disk error. 
  1533.  
  1534.                   BLOCK-READ       addr blk --                     :+ MAIN
  1535.                                   Read one block to addr.   Calls  the
  1536.                   function whose CFA is in @BLKRD  to  do  the  actual
  1537.                   transfer. 
  1538.  
  1539.                   BLOCK-WRITE      addr blk --                     :+ MAIN
  1540.                                   Write one block  from  addr.   Calls
  1541.                   the function whose CFA  is  in  @BLKWRT  to  do  the
  1542.                   actual transfer. 
  1543.  
  1544.                   BUFFER           n -- addr                       :* MAIN
  1545.                                   This function was modified to  flush
  1546.                   all dirty buffers when one is found. 
  1547.  
  1548.                   COLD             --                              :* MAIN
  1549.                                   Added code to  initialize  execution
  1550.                   vectors. 
  1551.  
  1552.  
  1553.           8086/8088 Fig-FORTH User's Guide                     Page 32
  1554.  
  1555.  
  1556.  
  1557.                   CR               --                              :* MAIN
  1558.                                   Output a carriage return/linefeed by
  1559.                   calling the function whose CFA is in @CR. 
  1560.  
  1561.                   CREATE           --                              :* MAIN
  1562.                                   Create a dictionary header  for  the
  1563.                   next word in the input stream.  CREATE was  modified
  1564.                   to align the address list.  The ALIGN option must be
  1565.                   selected for this to occur. 
  1566.  
  1567.                   D&RCALC          n --                            :+ DISK
  1568.                                   Set DRIVE and RECORD  for  block  n.
  1569.                   This function is called by BLKRD/BLKWRT  to  set  up
  1570.                   for (BLKRD)/(BLKWRT). 
  1571.  
  1572.                   DATE!            n1 n2 n3 --                     C+ XTNS
  1573.                                   Date set operator.   The  parameters
  1574.                   are  n1=month,  n2=day,  n3=year.   If  any  of  the
  1575.                   parameters are out of range, no change is made. 
  1576.  
  1577.                   DATE@            -- n1 n2 n3                     C+ XTNS
  1578.                                   Date fetch operator.  The parameters
  1579.                   are  n1=month,  n2=day,  n3=year.   If  any  of  the
  1580.                   parameters are out of range, no change is made. 
  1581.  
  1582.                   DISK             n -- n2                                 C+ FILE
  1583.                                   Set the current default drive to  n.
  1584.                   Drive A is zero, B is one.  The  number  of  drives,
  1585.                   n2, is left on the stack. 
  1586.  
  1587.                   DISK@            -- n                            C+ FILE
  1588.                                   Return  the  current  default  drive
  1589.                   number. 
  1590.  
  1591.                   DTA              -- addr                                 ?+ MAIN
  1592.                                   Variable holding the address of  the
  1593.                   last disk transfer operation.  This variable is  set
  1594.                   by R/W for use by the transfer functions. 
  1595.  
  1596.                   EMIT             c --                            :* MAIN
  1597.                                   Function  to  do  character  output.
  1598.                   Calls the function whose CFA is in @EMIT to  do  the
  1599.                   actual output. 
  1600.  
  1601.                   EMPTY-BUFFERS    --                              :* MAIN
  1602.                                   This function was  modified  to  set
  1603.                   emptied buffers to block 32767.  FIG-FORTH set  them
  1604.                   to zero. 
  1605.  
  1606.                   FLUSH            --                              :* MAIN
  1607.                                   FLUSH  was  also  modified  so  that
  1608.                   empty buffers are assigned to block 32767. 
  1609.  
  1610.  
  1611.           8086/8088 Fig-FORTH User's Guide                     Page 33
  1612.  
  1613.  
  1614.  
  1615.                   FDEL             FCB -- f                        C+ FILE
  1616.                                   Delete the file  specified  by  FCB.
  1617.                   The  flag  returned  is  zero  if  successful,  0FFH
  1618.                   otherwise. 
  1619.  
  1620.                   FREN             addr -- f                       C+ FILE
  1621.                                   Rename the  file  according  to  the
  1622.                   special FCB at addr.  See the DOS function  17H  for
  1623.                   details on how this is set up. 
  1624.  
  1625.                   KEY              -- c                            :+ MAIN
  1626.                                   Character input function.  KEY calls
  1627.                   the function  whose  CFA  is  in  @KEY  to  get  the
  1628.                   character. 
  1629.  
  1630.                   L!               n seg off --                    C+ XTNS
  1631.                   L@               seg off -- n                    C+ XTNS
  1632.                   LC!              n seg off --                    C+ XTNS
  1633.                   LC@              seg off -- b                    C+ XTNS
  1634.                                   Intersegment fetch/store  operators.
  1635.                   These are similar to  the  usual  FORTH  fetch/store
  1636.                   words, except they use a double-word address.   Note
  1637.                   that   the    absolute    location    accessed    is
  1638.                   seg*16+offset. 
  1639.  
  1640.                   MAXBLOCK         -- n                            #+ DISK
  1641.                                   Constant returning the highest legal
  1642.                   block number.  That is, BLK/DRIVE*(MAXDRIVE+1)-1. 
  1643.  
  1644.                   MAXDRIVE         -- n                            #+ DISK
  1645.                                   Constant returning the highest legal
  1646.                   drive number. 
  1647.  
  1648.                   MYSEG            -- seg                          C+ MYSEG
  1649.                                   This  word  returns  the  value   of
  1650.                   FORTH's  current  segment.   This  allows  the  long
  1651.                   fetch/store operators  to  access  locations  inside
  1652.                   FORTH easily. 
  1653.  
  1654.                   NFA              PFA -- NFA                      :* MAIN
  1655.                   PFA              NFA -- PFA                      :* MAIN
  1656.                                   These  functions  can   adjust   for
  1657.                   aligned definitions, if  ALIGN  is  selected  during
  1658.                   assembly. 
  1659.  
  1660.                   PRINTER          -- addr                                 ?+ MAIN
  1661.                                   Flag controlling printer output.  If
  1662.                   PRINTER is zero, nothing is sent to the printer.  If
  1663.                   PRINTER is positive, output to the console also goes
  1664.                   to the printer.   If  PRINTER  is  negative,  output
  1665.                   normally going to the console will be  sent  to  the
  1666.                   printer only.  Note that this is independent of  the
  1667.                   ^P/^N printer echo! 
  1668.  
  1669.  
  1670.           8086/8088 Fig-FORTH User's Guide                     Page 34
  1671.  
  1672.  
  1673.  
  1674.                   R/W              addr blk f --                   :* MAIN
  1675.                                   This function was modified to simply
  1676.                   pass the addr  and  blk  on  to  the  BLOCK-READ  or
  1677.                   BLOCK-WRITE functions. 
  1678.  
  1679.                   REC/BLK          -- n                            #+ DISK
  1680.                                   Constant  returning  the  number  of
  1681.                   disk records required to fill one 1024 byte  buffer.
  1682.                   All disk accesses look to FORTH like  they  transfer
  1683.                   1K of data. 
  1684.  
  1685.                   RECORD           -- addr                                 ?+ MAIN
  1686.                                   Variable  holding  the  disk  record
  1687.                   number where the last block  accessed  began.   That
  1688.                   is, if the last block accessed was  2,  then  record
  1689.                   would contain 2*REC/BLK.  This variable  is  set  by
  1690.                   D&RCALC for use by (BLKRD)/(BLKWRT). 
  1691.  
  1692.                   SAVBUF           addr --                                 :+ MAIN
  1693.                                   This function saves  the  buffer  at
  1694.                   addr if it has been updated.  The buffer is  flushed
  1695.                   but not emptied. 
  1696.  
  1697.                   SAVE-BUFFERS     --                              :+ MAIN
  1698.                                   This  function   flushes   all   the
  1699.                   buffers but doesn't  empty  them.   SAVE-BUFFERS  is
  1700.                   called by BUFFER when it finds a dirty buffer. 
  1701.  
  1702.                   TIME!            n1 n2 --                        C+ XTNS
  1703.                   TIME@            -- n1 n2                        C+ XTNS
  1704.                                   Set/fetch  the  system  time.    The
  1705.                   parameters  are  n1=[sec/csec],  n2=[hr/min];   each
  1706.                   quantity is a byte, but the four are packed  into  2
  1707.                   words.  Note that the low byte of the top stack item
  1708.                   has the minutes, the high byte holds the hours,  and
  1709.                   so on.  If any of the parameters are out  of  range,
  1710.           there is no effect.  
  1711.           8086/8088 Fig-FORTH User's Guide                     Page 35
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.           6.2  Deleted Definitions
  1718.  
  1719.                   The  following  words  were  deleted  from  the  FIG
  1720.                   listing:
  1721.  
  1722.                            EPRINT
  1723.                            SEC
  1724.                            SECRD
  1725.                            SECWT
  1726.                            SET-DRIVE
  1727.                            SET-IO
  1728.                            T&SCALC
  1729.                    TRACK 
  1730.           8086/8088 Fig-FORTH User's Guide                     Page 36
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.           6.3  High-level Extensions
  1737.  
  1738.                   The following words were added  by  compiling  FORTH
  1739.                   screens and saving the new version  of  FORTH.   The
  1740.                   FORTH source is included in the screen files. 
  1741.  
  1742.                   ARRAY            n --                            :+ ARRAYS.SCR
  1743.                   2ARRAY           n1 n2 --                        :+ ARRAYS.SCR
  1744.                                   One  and  two  dimensional   integer
  1745.                   array defining words.  Used as:
  1746.  
  1747.                            3 10 ARRAY WEIGHTS
  1748.  
  1749.                   to define a 3 by 10 array of integers which  can  be
  1750.                   accessed by:
  1751.  
  1752.                            0 0 WEIGHTS @  2 9 WEIGHTS ! 
  1753.  
  1754.                   Which would replace the last element by the first. 
  1755.  
  1756.                   STRING           n --                            :+ ARRAYS.SCR
  1757.                   STRINGS          n1 n2 --                        :+ ARRAYS.SCR
  1758.                                   One and two dimensional  byte  array
  1759.                   defining words.  Similar to  the  array  definitions
  1760.                   above, but are accessed by C@ and C!. 
  1761.  
  1762.                   CASE     OF ENDOF        ENDCASE                         :+ CASE.SCR
  1763.                                   These words add a case construct  to
  1764.                   FORTH.   They  have  been  documented   in   several
  1765.                   different places.  Quite a few examples are found in
  1766.                   the ASSEMBLER screens. 
  1767.  
  1768.                   DUMP             addr1 -- addr2                  :+ UTIL.SCR
  1769.                                   This word displays the  contents  of
  1770.                   memory from addr1 to addr2-1.  The address  left  on
  1771.                   the stack can be used to  continue  dumping  without
  1772.                   having to keep track of the address.   The  dump  is
  1773.                   given in the current number base.  A variable  named
  1774.                   SEGMENT is used as the base, with addr1  then  being
  1775.                   an offset in that segment.  SEGMENT  is  initialized
  1776.                   to MYSEG. 
  1777.  
  1778.                   NEW              --                              :+ UTIL.SCR
  1779.                                   NEW updates the start-up  parameters
  1780.                   to reflect the current state of FORTH.  This  allows
  1781.                   compiled definitions to be  retained  when  COLD  is
  1782.                   executed.  Note that if you FORGET the  added  words
  1783.                   after executing NEW, the start-up parameters will be
  1784.                   wrong, and NEW must  be  run  again  before  a  cold
  1785.                   start. 
  1786.  
  1787.  
  1788.           8086/8088 Fig-FORTH User's Guide                     Page 37
  1789.  
  1790.  
  1791.  
  1792.                   SIZE?            --                              :+ UTIL.SCR
  1793.                                   Shows the current size of the  FORTH
  1794.                   dictionary, and the free space remaining.   This  is
  1795.           primarily useful for saving modified FORTH's.  
  1796.           8086/8088 Fig-FORTH User's Guide                     Page 38
  1797.  
  1798.  
  1799.  
  1800.  
  1801.  
  1802.           7  Future Extensions
  1803.  
  1804.                   This version includes almost all of the extensions I
  1805.                   had planned to implement in the "immediate  future".
  1806.                   It will be work enough fixing bugs  and  tuning  the
  1807.                   revisions in  this  package,  without  shooting  for
  1808.                   major revisions. 
  1809.  
  1810.                   But, my list for  the  questionable  future  remains
  1811.                   intact:
  1812.  
  1813.                            Cross/target compiler
  1814.                            Code level floating point/8087 support
  1815.                            Multisegmented > 64K
  1816.                            Multitasking
  1817.                            Tree structured vocabularies/file system
  1818.                            High-level interrupt handling
  1819.  
  1820.                   Should any of  these  interest  you,  or  spark  any
  1821.                   comments,  I  would  be  happy  to  talk  or  trade.
  1822.                   Specifically, I would really love to have some  kind
  1823.                   of floating point package: this is  my  last  excuse
  1824.                   for writing ANYTHING in BASIC! 
  1825.  
  1826.                   The MACRO-86 assembler is really cumbersome at  this
  1827.                   kind of work, and FORTH is ideally suited to writing
  1828.                   new FORTH's.  If I can  get  metaFORTH  going,  that
  1829.           would make a nice project...  
  1830.           8086/8088 Fig-FORTH User's Guide                     Page 39
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.           8  FORTH sources
  1837.  
  1838.                   The following are sources of  information  regarding
  1839.                   the implementation and use of FORTH. 
  1840.  
  1841.  
  1842.                 * STARTING FORTH, by Leo Brodie.  Prentice Hall 1981
  1843.                   This is  probably  the  best  introductory  book  on
  1844.                   FORTH. 
  1845.  
  1846.  
  1847.                 * Byte, vol.  5 no.  8, August 1980
  1848.                   This issue was devoted to FORTH, and  contains  good
  1849.                   discussions of defining words and FORTH internals. 
  1850.  
  1851.                 * Dr.  Dobb's Journal, vol.  6 no.  9, September 1980
  1852.                   Dr.  Dobb's Journal, vol.  7 no.  9, September 1981
  1853.                   These issues were both devoted to FORTH topics. 
  1854.  
  1855.                 * Various publications of the Forth Interest Group:
  1856.                   Fig  FORTH  Installation  Guide,  FORTH   DIMENSIONS
  1857.                   bi-monthly journal. 
  1858.  
  1859.                 * Mountain View Press
  1860.                   P.O.  Box 4656, Mountain View, CA 94040
  1861.                   (415) 961-4103
  1862.                   This company has a large selection of  software  and
  1863.                   publications for sale. 
  1864.  
  1865.  
  1866.           8086/8088 Fig-FORTH User's Guide                     Page 40
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.                       Appendix A - Using execution vectors
  1873.  
  1874.  
  1875.  
  1876.           The i/o functions in this version of FORTH have been changed
  1877.           to use execution vectors.  An execution vector is  a  simple
  1878.           way to allow the user to substitute a different function for
  1879.           the function which is vectored in this way. 
  1880.  
  1881.  
  1882.           B.1  concepts
  1883.  
  1884.           The way an execution vector works is quite simple.   If  you
  1885.           are familiar with the concept of pointers to data,  this  is
  1886.           nothing new, for execution  vectors  are  only  pointers  to
  1887.           functions.  The pointer may be changed to hold  the  address
  1888.           of any function, and  as  long  as  the  specified  function
  1889.           expects and returns the same parameters and result,  no  one
  1890.           knows the difference. 
  1891.  
  1892.           The FORTH interpreter functions on this principle: it inputs
  1893.           a word, looks it up in the dictionary, and executes it.  The
  1894.           interpreter can totally ignore the action taken by the words
  1895.           it executes.  In standard FORTH, the function which executes
  1896.           a word is called EXEC.  The address that EXEC expects on the
  1897.           stack differs between FORTHs.   In  FIG-FORTH,  the  address
  1898.           must be a Code Field Address, or CFA.  The address  returned
  1899.           by the dictionary search words ( ' and -FIND) is a Parameter
  1900.           Field Address (PFA).   Thus,  to  look  up  a  word  in  the
  1901.           dictionary, you can type
  1902.  
  1903.                    ' MY-WORD
  1904.  
  1905.           but to find and execute MY-WORD, you would type
  1906.  
  1907.                    ' MY-WORD CFA EXEC
  1908.  
  1909.           This is totally equivalent to just typing MY-WORD. 
  1910.  
  1911.           In  this  way,  any  function  can  be  vectored  through  a
  1912.           variable: the variable holds the CFA of the function  to  be
  1913.           executed.  Instead of executing the function  directly,  the
  1914.           variable is fetched and the CFA stored  there  is  executed.
  1915.           Now, instead of jumping  directly  to  code  which  sends  a
  1916.           character to the console, KEY fetches the variable @KEY, and
  1917.           does whatever is at that CFA.  The definition of KEY is thus
  1918.  
  1919.                    : KEY @KEY @ EXEC ;
  1920.  
  1921.           To change the function of KEY, you just  store  a  different
  1922.           CFA in @KEY.  The new function can be defined after KEY, and
  1923.           any function which uses KEY will now call the new  function.
  1924.           The  danger  here  should  be  obvious:  if  the  substitute
  1925.  
  1926.           8086/8088 Fig-FORTH User's Guide                     Page 41
  1927.           Appendix A - Using execution vectors
  1928.  
  1929.  
  1930.  
  1931.           function doesn't have the same stack effects as the standard
  1932.           function, FORTH is going to get really confused. 
  1933.  
  1934.  
  1935.           B.2  An example
  1936.  
  1937.           Although this arrangement  is  slightly  more  complex,  the
  1938.           power and flexibility make it well worth the  extra  effort.
  1939.           The following example should make this clear. 
  1940.  
  1941.           Suppose you want to do all input in  capital  letters  only.
  1942.           You could write  your  own  specialized  input  routine,  or
  1943.           simply define an upper-case-only version of KEY and redirect
  1944.           KEY to that function.  Here is the definition  for  the  new
  1945.           KEY:
  1946.  
  1947.                    : UC-KEY
  1948.                         (KEY) DUP 96 > OVER 123 < AND
  1949.                         IF ( a-z )
  1950.                            32 -
  1951.                         THEN ;
  1952.  
  1953.           Now all you have  to  do  is  set  @KEY  to  point  to  your
  1954.           function:
  1955.  
  1956.                    ' UC-KEY CFA @KEY ! 
  1957.  
  1958.           and any lower case letter will be converted automatically to
  1959.           upper case.  To restore KEY to the original action,  restore
  1960.           @KEY to (KEY):
  1961.  
  1962.                    ' (KEY) CFA @KEY ! 
  1963.  
  1964.           Note that UC-KEY still calls (KEY)  to  get  the  character.
  1965.           While this is usually the case, it  is  not  necessary:  you
  1966.           could change KEY to get characters from any  source.   Also,
  1967.           be careful that you don't call the  vectored  function  from
  1968.           within your replacement.  If KEY had been  used  instead  of
  1969.           (KEY)  in  the  definition  above,  once   @KEY   had   been
  1970.           re-assigned you  would  have  a  good  example  of  infinite
  1971.           recursion!  Actually it isn't infinite - FORTH  dies  rather
  1972.           quickly... 
  1973.  
  1974.           This discussion applies to all  of  the  i/o  words,  except
  1975.           ?TERMINAL.  The block i/o functions are re-assigned in  this
  1976.           way to use the screen files.  There are more elegant ways of
  1977.           implementing execution vectors, which bypass  the  need  for
  1978.           separate variables, but  they  require  new  defining  words
  1979.           which  would  have  been  inconvenient  to  define  in   the
  1980.           assembler source.  
  1981.           8086/8088 Fig-FORTH User's Guide                     Page 42
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.                         Appendix B - Building FORTH.COM
  1988.  
  1989.  
  1990.  
  1991.           The following example serves several  functions.   It  is  a
  1992.           real session with FORTH, it shows how the FORTH.COM file was
  1993.           constructed, and, it demonstrates how to modify and save new
  1994.           versions of FORTH. 
  1995.  
  1996.           After assembling the FORTH source, you are left with a  bare
  1997.           kernel.  To add the  utilities,  editor  and  file  handling
  1998.           functions, several things have to be done:
  1999.  
  2000.                1) The file interface screens must be transferred to  a
  2001.                   FORTH disk.  This process involves  using  DEBUG  to
  2002.                   load the file and write it to the FORTH disk. 
  2003.  
  2004.                2) The file interface is LOADed from the FORTH disk. 
  2005.  
  2006.                3) The utilities and editor  are  /LOAD"ed  from  their
  2007.                   files. 
  2008.  
  2009.                4) FORTH is reset to make the additions permanent,  and
  2010.                   the version number is changed. 
  2011.  
  2012.                5) The utilities for saving FORTH are loaded  and  used
  2013.                   to write the new FORTH to a .COM file. 
  2014.  
  2015.           The following session was  copied  from  a  listing  of  the
  2016.           commands to build FORTH.COM.   An  ellipsis  indicates  that
  2017.           part of the listing has been left out. 
  2018.  
  2019.           This example assumes that you have a FORTH disk in drive  A,
  2020.           and your FORTH system disk with  FORTH.COM  and  the  screen
  2021.           files in drive B. 
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.                    B:DEBUG FILES.SCR
  2028.                    -W 100 0 64 20
  2029.                    -Q
  2030.                    B:
  2031.  
  2032.           Here, DEBUG has loaded the MS-DOS file interface screens  in
  2033.           FILES.SCR and then written the screens to disk A starting at
  2034.           screen 100.  This assumes that one record holds one  screen.
  2035.           You will have to adjust the record numbers if  this  is  not
  2036.           the case. 
  2037.  
  2038.           8086/8088 Fig-FORTH User's Guide                     Page 43
  2039.           Appendix B - Building FORTH.COM
  2040.  
  2041.  
  2042.  
  2043.                    B:4TH
  2044.  
  2045.                    8086 Fig-FORTH Version 1.0A
  2046.                    100 LOAD 102 LOAD BYE MSG # 4 ok
  2047.                    LATEST ID.  LOAD" ok
  2048.  
  2049.           After assembling FORTH and grabbing a snack while MASM chugs
  2050.           along, the resulting 4TH.COM is started.  The  newly  copied
  2051.           screens residing on disk A are loaded,  the  last  word  now
  2052.           being LOAD". 
  2053.  
  2054.  
  2055.  
  2056.  
  2057.  
  2058.                    USING" FUTIL" last block in B:FUTIL.SCR is 10 ok
  2059.                    1 LOAD ok
  2060.                    2 LOAD ok
  2061.                    3 LOAD .DIR MSG # 4 ok
  2062.                    7 LOAD ok
  2063.                    LATEST ID.  COPY>SCR ok
  2064.                    EOF B:FUTIL .SCR 11264 07-19-1983 2:37 ok
  2065.  
  2066.           The file interface allows FORTH to  use  the  screen  files.
  2067.           The utilities for listing the directory  and  erasing  files
  2068.           are loaded.  Also, the words for copying screens to and from
  2069.           FORTH disks are loaded from screen 7. 
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.                    USING" UTIL" last block in B:UTIL.SCR is 8 ok
  2076.                    8 LOAD ok
  2077.                    3 LOAD 4 LOAD 6 LOAD ok
  2078.                    WORDS
  2079.  
  2080.                    CURRENT and CONTEXT are FORTH
  2081.                    WORDS   TAB     TABSTOP         MORE?   DLIST   NEW     SIZE? 
  2082.                    BASE?   VOC?    VOC.    S?      DEPTH   ENDCASE         ENDOF
  2083.                    OF      CASE    #SCRCOPY        SCRCOPY         ASSIGN-BUF
  2084.                    COPY>SCR        COPY>FILE       PAUSE   ERASE"
  2085.                    . 
  2086.                    . 
  2087.                    . 
  2088.                    EOF B:UTIL .SCR 9216 07-20-1983 19:18 ok
  2089.  
  2090.           More utilities, including  NEW  to  update  the  COLD  start
  2091.           parameters, are loaded  from  the  UTIL  screen  file.   The
  2092.           vocabulary listing word WORDS is tested, and then  the  file
  2093.           is closed. 
  2094.  
  2095.           8086/8088 Fig-FORTH User's Guide                     Page 44
  2096.           Appendix B - Building FORTH.COM
  2097.  
  2098.  
  2099.  
  2100.                    LOAD" EDITOR" last block in B:EDITOR.SCR is 6
  2101.  
  2102.                            FORTH, Inc.  editor
  2103.                    . 
  2104.                    . 
  2105.                    . 
  2106.                            editor loading, please wait... 
  2107.  
  2108.                    I MSG # 4 R MSG # 4
  2109.  
  2110.                    Current screen is 8 B:EDITOR .SCR 7168 07-19-83 2:53 ok
  2111.  
  2112.           The editor described in STARTING FORTH is loaded.  Note that
  2113.           LOAD" first lists screen 0, then begins loading at screen 1,
  2114.           and finally closes the file when the load is complete. 
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.                    NEW
  2121.                    current version is A
  2122.                    new version (A-Z)?  Bok
  2123.                    USING" FUTIL" last block in B:FUTIL.SCR is 10 ok
  2124.                    4 LOAD ok
  2125.                    EOF B:FUTIL .SCR 11264 07-20-1983 19:32 ok
  2126.  
  2127.           Here, the utilities to save FORTH are loaded.  Note that any
  2128.           words defined after executing NEW will not  be  saved,  and,
  2129.           that the file is closed before writing the new version. 
  2130.  
  2131.                    >FILE S4
  2132.                    S4 /SAVE-FORTH" FORTH.COM"
  2133.                    B:FORTH .COM - w c 13687 07-20-1983 19:41 ok
  2134.                     ok
  2135.                    BYE
  2136.                    B:FORTH
  2137.  
  2138.                    8086 Fig-FORTH Version 1.0B
  2139.                    WORDS
  2140.  
  2141.                    WHERE   EDITOR  LINE    TEXT    WORDS... 
  2142.  
  2143.                    EDITOR WORDS
  2144.  
  2145.                    r       u       i       s       f... 
  2146.  
  2147.                    BYE
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.           Thats all, folks!